/****************************************************************************
 **
 ** Copyright (C) 2004-2008 Trolltech ASA. All rights reserved.
 **
 ** This file is part of the documentation of the Qt Toolkit.
 **
 ** This file may be used under the terms of the GNU General Public
 ** License versions 2.0 or 3.0 as published by the Free Software
 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
 ** included in the packaging of this file.  Alternatively you may (at
 ** your option) use any later version of the GNU General Public
 ** License if such license has been publicly approved by Trolltech ASA
 ** (or its successors, if any) and the KDE Free Qt Foundation. In
 ** addition, as a special exception, Trolltech gives you certain
 ** additional rights. These rights are described in the Trolltech GPL
 ** Exception version 1.2, which can be found at
 ** http://www.trolltech.com/products/qt/gplexception/ and in the file
 ** GPL_EXCEPTION.txt in this package.
 **
 ** Please review the following information to ensure GNU General
 ** Public Licensing requirements will be met:
 ** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
 ** you are unsure which license is appropriate for your use, please
 ** review the following information:
 ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
 ** or contact the sales department at sales@trolltech.com.
 **
 ** In addition, as a special exception, Trolltech, as the sole
 ** copyright holder for Qt Designer, grants users of the Qt/Eclipse
 ** Integration plug-in the right for the Qt/Eclipse Integration to
 ** link to functionality provided by Qt Designer and its related
 ** libraries.
 **
 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
 ** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
 ** granted herein.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ****************************************************************************/

#ifndef KEYCONFIGDIALOG_H
#define KEYCONFIGDIALOG_H

#include <QDialog>

class QLabel;
class QComboBox;

/// Class holding all of the keyconfig realated items
class KeyConfig
{
public:
  /// Maps a keycode to the Qt equivalent
  struct KeyCodeMapEntry
  {
      const char *name; /*!< Human readable string to print in config dialog */
      int qtKeycode; /*!< Qt key value to map to */
  };

  /// Keycodes
  typedef enum
  {
      Key_A = 0, Key_B,  Key_C, Key_D, Key_E, Key_F, Key_G, Key_H, Key_I,
      Key_J, Key_K, Key_L, Key_M, Key_N, Key_O, Key_P, Key_Q, Key_R, Key_S,
      Key_T, Key_U, Key_V, Key_W, Key_X, Key_Y, Key_Z, Key_0, Key_1, Key_2,
      Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_Left, Key_Right,
      Key_Up, Key_Down, Key_Space, NumKeycodes
  } KeyCode;

  /// Array holding all of the keycodes
  static struct KeyCodeMapEntry qtKeyMap[];
};

/// Modal dialog to select the key configuration
class KeyConfigDialog : public QDialog
{
    Q_OBJECT

public:
    KeyConfigDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);

    /*!
     * @return KeyCode for rotate action
     */
    KeyConfig::KeyCode rotateKey() const { return rotate; }
    /*!
     * @return KeyCode for left action
     */
    KeyConfig::KeyCode leftKey() const { return left; }
    /*!
     * @return KeyCode for right action
     */
    KeyConfig::KeyCode rightKey() const { return right; }
    /*!
     * @return KeyCode for fall action
     */
    KeyConfig::KeyCode fallKey() const { return fall; }

protected:
    virtual void showEvent(QShowEvent *event);

private slots:
    void okButtonClicked();
    void cancelButtonClicked();

private:
    QLabel *createLabel(const QString &text);

    QPushButton *okButton;
    QPushButton *cancelButton;
    QComboBox *rotateComboBox;
    QComboBox *leftComboBox;
    QComboBox *rightComboBox;
    QComboBox *fallComboBox;
    KeyConfig::KeyCode rotate;
    KeyConfig::KeyCode left;
    KeyConfig::KeyCode right;
    KeyConfig::KeyCode fall;
};

#endif
